package com.xunfang.controller;

import com.xunfang.bean.MenuVo;
import com.xunfang.common.Result;
import com.xunfang.service.IMenuService;
import com.xunfang.utils.JwtTemplate;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author yellow Docter
 * @date 2023 -11-01
 * @desc
 */
@Slf4j
@RestController
@Api
@RequestMapping("menu")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    @Autowired
    private JwtTemplate jwtTemplate;

    @GetMapping("list")
    public Result findMenuByUsername(HttpServletRequest request){

        //如何获取admin （用户信息） token
        String token = request.getHeader("token");

        String username = (String) jwtTemplate.parseToken(token, "username");
        log.info("获取token的用户的名称:{}",username);
        List<MenuVo> menuVos = menuService.findMenuByUsername(username);
        return Result.ok(menuVos);
    }

}
